package com.molyfun.parents.fragment.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.molyfun.parents.R;

/**
 * Created by Administrator on 2017/11/11 0011.
 */

public class SignUpSeccessDialogFragment extends Dialog {

    public SignUpSeccessDialogFragment(Context context) {
        super(context);
    }
    public SignUpSeccessDialogFragment(Context context, int theme) {
        super(context, theme);
    }

    public static class Builder {
        public String message;
        private View contentView;
        private String positiveButtonText;
        private String negativeButtonText;
        private String singleButtonText;
        private View.OnClickListener positiveButtonClickListener;
        private View.OnClickListener negativeButtonClickListener;
        private View.OnClickListener singleButtonClickListener;

        private View layout;
        private SignUpSeccessDialogFragment dialog;
        public Builder(Context context) {
            //这里传入自定义的style，直接影响此Dialog的显示效果。style具体实现见style.xml
            dialog = new SignUpSeccessDialogFragment(context, R.style.msg_sign_up_dialog_style);
            LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            layout = inflater.inflate(R.layout.dialog_organization_sign_up, null);
            dialog.addContentView(layout, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));

        }

        public Builder setMessage(String message) {
            this.message = message;
            return this;
        }

        public Builder setContentView(View v) {
            this.contentView = v;
            return this;
        }

        public Builder setPositiveButton(String positiveButtonText, View.OnClickListener listener) {
            this.positiveButtonText = positiveButtonText;
            this.positiveButtonClickListener = listener;
            return this;
        }

        public Builder setNegativeButton(String negativeButtonText, View.OnClickListener listener) {
            this.negativeButtonText = negativeButtonText;
            this.negativeButtonClickListener = listener;
            return this;
        }

        public Builder setSingleButton(String singleButtonText, View.OnClickListener listener) {
            this.singleButtonText = singleButtonText;
            this.singleButtonClickListener = listener;
            return this;
        }

        /**
         * 创建单按钮对话框
         * @return
         */
        public SignUpSeccessDialogFragment createSingleButtonDialog() {
            layout.findViewById(R.id.close_button).setOnClickListener(singleButtonClickListener);
            //如果传入的按钮文字为空，则使用默认的“返回”
            if (singleButtonText != null) {
                ((TextView) layout.findViewById(R.id.close_button)).setText(singleButtonText);
            }
            create();
            return dialog;
        }

        /**
         * 单按钮对话框和双按钮对话框的公共部分在这里设置
         */
        private void create() {
            if (message != null) {      //设置提示内容
                ((TextView) layout.findViewById(R.id.line_up_num)).setText(message);
            }else {
                ((TextView) layout.findViewById(R.id.line_up_num)).setText("当前没有排名");
            }
            dialog.setCancelable(true);     //用户可以点击手机Back键取消对话框显示
            dialog.setCanceledOnTouchOutside(false);        //用户不能通过点击对话框之外的地方取消对话框显示
        }

        private void showTitleButton() {
            layout.findViewById(R.id.title).setVisibility(View.VISIBLE);
        }
        private void hitTitleButton() {
            layout.findViewById(R.id.title).setVisibility(View.GONE);
        }
        public Builder hitLineUpLayout() {
            layout.findViewById(R.id.line_up_layout).setVisibility(View.GONE);
            return this;
        }
        public Builder showLineUp(String count) {
            TextView textView = (TextView) layout.findViewById(R.id.line_up_num);
            textView.setText(count);
            return this;
        }

    }
}